package edu.ccut.titan.tag.report.tag;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import edu.ccut.titan.tag.report.design.ReportFieldInfo;

public class TitanReportFieldTag extends TagSupport {
	private static final long serialVersionUID = 1L;
	private String title;
	private String property;
	private String width;
	private String type;
	private String express;
	private TitanReportTag report;

	@Override
	public int doStartTag() throws JspException {
		report = (TitanReportTag) this.getParent();
		report.addDesignInfo(getField());
		
		return EVAL_BODY_INCLUDE;
	}

	@Override
	public int doEndTag() throws JspException {
		return SKIP_BODY;
	}
	
	public ReportFieldInfo getField(){
		ReportFieldInfo field = new ReportFieldInfo();
		if (!"".equals(this.title) && this.title != null) {
			field.setTitle(this.title);
		}
		if (!"".equals(this.property) && this.property != null) {
			field.setKey(this.property);
		}
		if (!"".equals(this.width) && this.width != null) {
			field.setWidth(Integer.parseInt(this.width));
		}
		if (!"".equals(this.type) && this.type != null) {
			field.setClassName(this.type);
		}
		if (!"".equals(this.express) && this.express != null) {
			field.setExpress(this.express);
		}
		return field;
	}

	public String getTitle() {
		if (title != null) {
			return title;
		} else {
			return "";
		}
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getProperty() {
		if (property != null) {
			return property;
		} else {
			return "";
		}
	}

	public void setProperty(String property) {
		this.property = property;
	}

	public String getWidth() {
		if (width != null) {
			return width;
		} else {
			return "";
		}
	}

	public void setWidth(String width) {
		this.width = width;
	}

	public String getType() {
		if (type != null) {
			return type;
		} else {
			return "";
		}
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getExpress() {
		if (express != null) {
			return express;
		} else {
			return "";
		}
	}

	public void setExpress(String express) {
		this.express = express;
	}
}
